package controller

import (
	"bluebell/logic"
	"bluebell/models"
	"github.com/gin-gonic/gin"
	"github.com/go-playground/validator/v10"
)

func PostVoteHandler(ctx *gin.Context) {
	param := new(models.ParamVoteData)
	if err := ctx.ShouldBindJSON(param); err != nil {
		errs, ok := err.(validator.ValidationErrors)
		if !ok {
			ResponseError(ctx, 400, "参数有误")
			return
		}
		errData := removeTapStruct(errs.Translate(trans))
		ResponseError(ctx, 400, errData)
		return
	}
	userID, err := getCurrentUserID(ctx)
	if err != nil {
		ResponseError(ctx, 400, "服务器繁忙")
	}
	// 逻辑层处理
	if err := logic.PostVote(userID, param); err != nil {
		ResponseError(ctx, 400, err.Error())
		return
	}
	ResponseSuccess(ctx, 200, "投票操作成功", nil)
}
